<?php

namespace App\Admin\Controllers;

use App\Models\TcmPrescriptionDetail;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class TcmPrescriptionDetailController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new TcmPrescriptionDetail(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name');
			$grid->column('picture')->image('',50,50);
            $grid->column('source');

            //$grid->column('shareImg');
            
            //$grid->column('ancientDose');
            //$grid->column('modernDose');
            //$grid->column('decoction');
            //$grid->column('ballad');
            //$grid->column('indications');
            //$grid->column('adjustment');
            //$grid->column('explanation');
            //$grid->column('created_at');
            //$grid->column('updated_at')->sortable();
        
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
        
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new TcmPrescriptionDetail(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('source');
            //$show->field('effects');
            $show->field('shareImg')->image('',50,50);
            $show->field('picture')->image('',50,50);

            $show->field('ancientDose')->unescape()->as(function ($html) {
				return $html;
			});
			$show->field('modernDose')->unescape()->as(function ($html) {
				return $html;
			});
			$show->field('decoction');
			$show->field('ballad')->json();
			$show->field('indications')->unescape()->as(function ($html) {
				return $html;
			});
			$show->field('adjustment')->unescape()->as(function ($html) {
				return $html;
			});
			
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new TcmPrescriptionDetail(), function (Form $form) {
			$form->tab('基本信息', function (Form $form) {
				$form->display('id');
				$form->text('name');
				$form->text('source');
				$form->image('picture')->uniqueName()->autoUpload()->saveFullUrl();
				$form->image('shareImg')->uniqueName()->autoUpload()->saveFullUrl();
			});
			$form->tab('古代剂量', function (Form $form) {
				$form->editor('ancientDose');
			});
			
			$form->tab('现代剂量', function (Form $form) {
				$form->editor('modernDose');
			});
			
			$form->tab('煎服法', function (Form $form) {
				 $form->text('decoction');
			});
			
			$form->tab('方歌', function (Form $form) {
				$form->array('ballad','', function ($table) {
					$table->text('title','标题');
					$table->text('content','内容');
					$table->text('author','作者');
				})->saving(function ($v) {
					return json_encode($v,JSON_UNESCAPED_UNICODE);
				});
			});
			
			$form->tab('主治', function (Form $form) {
				$form->editor('indications');
			});
			
			$form->tab('随证化裁', function (Form $form) {
				$form->editor('adjustment');
			});
        
            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
